import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.ArrayList;

/**
 * Represents sentence as sequence of tokens.
 */
public class Sentence extends TextElement
{
    /**
     * Sequence of text tokens.
     */
    public ArrayList<Token> tokens;

    /**
     * Construct from DOM element.
     */
    public Sentence(Element sentenceElement, Article parentArticle) throws Throwable
    {
        // initialize 'TextElement'
        id = sentenceElement.getAttribute("id");
        parent = parentArticle;

        // recursively build sequence of tokens
        NodeList tokenNodes = sentenceElement.getChildNodes();
        tokens = new ArrayList<Token>(tokenNodes.getLength());
        for (int i = 0; i < tokenNodes.getLength(); i++)
        {
            Element tokenElem = (Element) tokenNodes.item(i);
            tokens.add(new Token(tokenElem, this));
        }
    }
}
